package com.dycx.api.controller.manage.cms;

import com.dycx.cms.dto.AdDTO;
import com.dycx.cms.service.AdService;
import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController
@RequestMapping(value = "/manage/cms/ad")
public class AdController {

    @Resource
    private AdService adService;

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD, bizValue = "{#id}",logTitle = "删除广告")
    @GetMapping("/delete")
    public RestResponse<?> delete(int id) {
        return adService.delete(id) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD, bizValue = "{#adDto.id}",logTitle = "添加广告")
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody @Valid AdDTO adDto) {
        return adService.add(adDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD, bizValue = "{#adDto.id}",logTitle = "修改广告")
    @PostMapping("/edit")
    public RestResponse<?> edit(@RequestBody @Valid AdDTO adDto) {
        return adService.edit(adDto) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 分页
     **/
    @PostMapping("/getPage")
    public RestResponse<?> getPage(@RequestBody AdDTO adDto) {
        return RestResponse.success(adService.getPage(adDto));
    }

    /**
     * 修改排序
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD, bizValue = "{#adDto.id}",logTitle = "修改排序")
    @PostMapping("/updateSort")
    public RestResponse<?> updateSort(@RequestBody AdDTO adDto) {
        return RestResponse.success(adService.updateSort(adDto));
    }

    /**
     * 修改状态
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD, bizValue = "{#adDto.id}",logTitle = "更新状态")
    @PostMapping("/updateStatus")
    public RestResponse<?> updateStatus(@RequestBody AdDTO adDto) {
        return RestResponse.success(adService.updateStatus(adDto));
    }
}
